﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">类型编码</label>
                <div class="layui-input-inline">
                    <input type="text" name="toolTypeCode" lay-verify="required" disabled placeholder="请输入库位编号" autocomplete="off" class="layui-input" id="toolTypeCode">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="toolTypeName" lay-verify="required" placeholder="请输入库位名称" autocomplete="off" class="layui-input" id="toolTypeName">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width:auto">是否单独编码管理</label>
                <div class="layui-input-inline" style="width: 180px;">
                    <input type="radio" name="codeFlag" id="Y" value="Y" title="是">
                    <input type="radio" name="codeFlag" id="N" value="N" title="否">
                </div>
                <label class="layui-form-label" style="width:auto">保养维护类型</label>
                <div class="layui-input-inline">
                    <select name="maintenType" id="maintenType" lay-filter="aihao">
                        <option value=""></option>
                        <option value="定期维护">定期维护</option>
                        <option value="按使用次数维护">按使用次数维护</option>
                    </select>
                </div>
                <label class="layui-form-label">保养周期</label>
                <div class="layui-input-inline">
                    <input type="text" name="maintenPeriod" id="maintenPeriod" lay-verify="required" placeholder="请输入保养周期" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" id="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
            <input type="text" id="id" class="layui-input" style="display: none;" placeholder="隐藏Id的文本框">
            <input type="text" id="createTime" class="layui-input" style="display: none;" placeholder="隐藏的创建时间的文本框">
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>

    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            //反填表单数据
            function getchildIframeData() {
                $("#toolTypeCode").val(parent.toolTypeCode);
                $("#toolTypeName").val(parent.toolTypeName);
                if (parent.codeFlag == "Y") {
                    $("#Y").prop("checked", true);
                } else {
                    $("#N").prop("checked", true);
                }
                $("#maintenType").val(parent.maintenType);
                $("#maintenPeriod").val(parent.maintenPeriod);
                $("#remark").val(parent.remark);
                $("#id").val(parent.id);
                $("#createTime").val(parent.createTime);
                form.render("select");//重新渲染表单
                form.render();//重新渲染表单
            }

            getchildIframeData();

            // 提交事件
            form.on('submit(demo1)', function (data) {

                var field = data.field; // 获取表单字段值
                field.Id = $("#id").val(); // 追加Id字段值
                field.CreateTime = $("#createTime").val(); // 追加创建时间字段值
                $.get('/Zhou/UpdateToolType', field, function (res) {
                    if (res > 0) {
                        layer.msg('保存成功', {
                            icon: 1,
                            time: 500
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index);//再执行关闭
                        });
                    } else {
                        layer.msg("网络异常");
                    }
                });
                return false; // 阻止默认 form 跳转
            });

        });
    </script>

</body>
</html>